import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-07-17
 * Time: 20:05
 */
public class JDBC_Insert {
    public void Insert(Connection connection) throws SQLException {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入id:");
        int id=scanner.nextInt();
        System.out.println("请输入姓名:");
        String name=scanner.next();

        String sql="insert into student values(?,?)";

        PreparedStatement statement=connection.prepareStatement(sql);
        statement.setInt(1,id);
        statement.setString(2,name);

        int n=statement.executeUpdate();
        System.out.println("n="+n);

        statement.close();
        connection.close();
    }
}
